package com.dinghui.ebookbag.module.middle;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
import androidx.appcompat.app.AppCompatActivity;
import com.dinghui.ebookbag.R;
import com.dinghui.ebookbag.config.Constants;

public class VideoPlayActivity extends AppCompatActivity {

    private VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_play);
        initView();
        initData();
    }

    private void initView() {
        videoView = (VideoView) findViewById(R.id.video_view);
    }

    private void initData() {
        // 使用Intent对象得到MainActivity中传过来的参数
        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        String videoImage = intent.getStringExtra("videoImage");

        String finalUrl = Constants.API.BASE_IMAGE + url;

        // 设置地址
        //videoView.setVideoURI(Uri.parse(finalUrl));
        videoView.setVideoPath(finalUrl);
        videoView.start();
        // 使用 MediaController 控制视频播放
        MediaController mediaController = new MediaController(this);
        // 设置VideoView和MediaController建立关系
        videoView.setMediaController(mediaController);
        // 设置MediaController和VideoView建立关系
        mediaController.setMediaPlayer(videoView);
    }
}
